/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Database;

import callcenter.Medium;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.Vector;

/**
 *
 * @author DELL INSPIRON N5010
 */
public class DetailPurchaseBill 
{
    private int BillId;
    private int ProduceId;
    private double Price;
    private String Unit;
    private int Quantily;
    private String Description;

    /**
     * @return the BillId
     */
    public int getBillId() {
        return BillId;
    }

    /**
     * @param BillId the BillId to set
     */
    public void setBillId(int BillId) {
        this.BillId = BillId;
    }

    /**
     * @return the ProduceId
     */
    public int getProduceId() {
        return ProduceId;
    }

    /**
     * @param ProduceId the ProduceId to set
     */
    public void setProduceId(int ProduceId) {
        this.ProduceId = ProduceId;
    }

    /**
     * @return the Price
     */
    public double getPrice() {
        return Price;
    }

    /**
     * @param Price the Price to set
     */
    public void setPrice(double Price) {
        this.Price = Price;
    }

    /**
     * @return the Unit
     */
    public String getUnit() {
        return Unit;
    }

    /**
     * @param Unit the Unit to set
     */
    public void setUnit(String Unit) {
        this.Unit = Unit;
    }

    /**
     * @return the Quantily
     */
    public int getQuantily() {
        return Quantily;
    }

    /**
     * @param Quantily the Quantily to set
     */
    public void setQuantily(int Quantily) {
        this.Quantily = Quantily;
    }

    /**
     * @return the Description
     */
    public String getDescription() {
        return Description;
    }

    /**
     * @param Description the Description to set
     */
    public void setDescription(String Description) {
        this.Description = Description;
    }
    public boolean Adddetailpurchasebill()
    {
        boolean result=true;
        try
        {
            Connection con=ConecttoDatabase.getConnection();
            String query="insert into DetailPurchaseBill values(?, ?, ?, ?, ?)";
            PreparedStatement ps=con.prepareCall(query);
            ps.setInt(1, this.BillId);
            ps.setInt(2, this.ProduceId);
            ps.setDouble(3, this.Price);
            ps.setInt(4, this.Quantily);
            ps.setString(5, this.Description);
            result=ps.executeUpdate()>0;
        }
        catch(Exception ex)
        {
            System.out.println(ex);
            result =false;
            
        }
        return result;
        } 
     public Vector<Vector<Object>> createtabledetailpurcharbill()
    {
        Vector<Vector<Object>> lisdetailpurcharbill=new Vector<Vector<Object>>();
        try
        {
            Connection con=ConecttoDatabase.getConnection();
            String query="select t3.ProductName,t2.Price,t2.Quantily,t2.Description from PurchaseBill t1, DetailPurchaseBill t2, Product t3 where t1.BillId=t2.BillId and t2.ProductId=t3.ProductId and t2.BillId=?";
            //Statement st=con.createStatement();
            PreparedStatement ps=con.prepareCall(query);
            ps.setInt(1, Medium.jifsb1.getselectedpurchasebillid());
            ResultSet rs=ps.executeQuery();
            while(rs.next())
            {
                Vector<Object> rows=new Vector<Object>();
                //rows.add(rs.getInt("ProductId"));
                rows.add(rs.getString("ProductName"));
                rows.add(rs.getDouble("Price"));
                rows.add(rs.getInt("Quantily"));
                rows.add(rs.getString("Description"));
                
                lisdetailpurcharbill.add(rows);
            }
        }
        catch(Exception ex)
        {
            System.out.println(ex);
            lisdetailpurcharbill=null;
        }
        return lisdetailpurcharbill;
    }
    public boolean DeletedetailBpurcharbill()
    {
        boolean result=true;
        try
        {
            Connection con=ConecttoDatabase.getConnection();
            String query="delete from DetailPurchaseBill where ProductId=?";
            PreparedStatement ps=con.prepareCall(query);
            ps.setInt(1, ProduceId);
            result=ps.executeUpdate()>0;
        }
        catch(Exception ex)
        {
            result=false;
            System.out.println("sai o day"+ex);
        }
        return result;
    }
}
